package sz.szsmk.citizencard.ui.newversion.fragment.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import jp.wasabeef.glide.transformations.RoundedCornersTransformation
import kotlinx.android.synthetic.main.layout_homebottommodule.view.*
import kotlinx.android.synthetic.main.layout_homebottommodule.view.iv_img
import kotlinx.android.synthetic.main.layout_homebottommodule.view.tv_title
import kotlinx.android.synthetic.main.layout_homeusermodule.view.*
import sz.szsmk.citizencard.R
import sz.szsmk.citizencard.model.network.clarkbean.response.AdInfo
import sz.szsmk.citizencard.util.GlideRoundTransform
import sz.szsmk.citizencard.util.JumpThirdView
import java.math.BigDecimal

/**
 *  author : hyt
 *  date : 2020/8/31
 *  description :
 */
class HomeBottomAdapter(var mContext: Context? = null):
        RecyclerView.Adapter<HomeBottomAdapter.BottomModuleHolder>() {

    var datas = mutableListOf<AdInfo>()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
            BottomModuleHolder(LayoutInflater.from(mContext)
                    .inflate(R.layout.layout_homebottommodule, parent, false))

    override fun getItemCount() = datas.size

    override fun onBindViewHolder(holder: BottomModuleHolder, position: Int) {
        var temp = datas[position]
            Glide.with(mContext).load(temp.resource_url)
                .transform(GlideRoundTransform(mContext))
                .into(holder.itemView.iv_img)

        holder.itemView.iv_img.setOnClickListener {
            
            JumpThirdView.baseToJumpView(mContext,temp.link_url,temp.sys_label, temp.need_header,"")
        }

        holder.itemView.tv_title.text = temp.resource_name
        holder.itemView.tv_subtitle.text = temp.resource_description


        //获取余额
        var bignum1: BigDecimal = BigDecimal(temp?.resource_price)
        var bignum3 = bignum1.divide(BigDecimal(100))
        var bignum4 = bignum3.setScale(2)
        holder.itemView.tv_money.text = "¥${ bignum4 }"
    }

    fun addDatas(datas: List<AdInfo>){
        this.datas.clear()
        this.datas.addAll(datas)
        notifyDataSetChanged()
    }

    class BottomModuleHolder(var view: View)
        : RecyclerView.ViewHolder(view)
}